package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.activity.home.HomeActivity1;
import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.CheckBean;
import com.mz.ozy.bean.HomeMerBean;
import com.mz.ozy.bean.ObShopBean;
import com.mz.ozy.bean.UnreadMsgBean;
import com.mz.ozy.mvp.model.HomeModel;
import com.mz.ozy.mvp.view.HomeContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;


/**
 * @author
 * @date 2018/7/25
 * @description
 */

public class HomePresenter extends BasePresenterImpl<HomeContract.View> implements HomeContract.Presenter {
    private HomeModel mHomeModel;

    public HomePresenter() {
        super();
        mHomeModel = new HomeModel();
    }

    @Override
    public void getMyMer(Activity activity) {
        mHomeModel.getMyMer(activity).
                compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<HomeMerBean>(mView, false) {
                    @Override
                    public void onSuccesss(HomeMerBean homeMerBean) {
                        mView.getMyMerSuccess(homeMerBean);

                    }
                });
    }

    @Override
    public void checkUpdateVersion(Activity activity) {
        mHomeModel.checkUpdateVersion(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<CheckBean>(mView) {

                    @Override
                    public void onSuccesss(CheckBean jsonObject) {
                        mView.checkUpdateVersionSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void getOrMer(Activity activity) {
        mHomeModel.getOrMer(activity).
                compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<HomeMerBean>(mView, false) {
                    @Override
                    public void onSuccesss(HomeMerBean homeMerBean) {
                        mView.getOrSuccess(homeMerBean);

                    }
                });
    }

    @Override
    public void getHomeInfo(Context context, boolean isFirst) {
        mHomeModel.getHomeInfo(context).
                compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<HomeMerBean>(mView, isFirst) {
                    @Override
                    public void onSuccesss(HomeMerBean homeMerBean) {
                        mView.getHomeInfoSuccess(homeMerBean);

                    }
                });
    }

    public void exitLogin(Context context) {
        mHomeModel.exitLogin(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.exitLoginSuccess(bean);
                    }
                });
    }

    @Override
    public void getUnreadMsg(Context context) {
        mHomeModel.getUnreadMsg(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<UnreadMsgBean>(mView) {
                    @Override
                    public void onSuccesss(UnreadMsgBean bean) {
                        mView.getUnreadMsgSuccess(bean);
                    }
                });
    }

    @Override
    public void getProduct(Context context, String pageNo) {
        mHomeModel.getProduct(context,pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<ObShopBean>(mView) {
                    @Override
                    public void onSuccesss(ObShopBean bean) {
                        mView.getProductSuccess(bean);
                    }
                });
    }
}
